<div class="container">
    <h1 id="pkg-overview">package expvar</h1>
    <p><code>import "expvar"</code>
    </p><p align="left">expvar包提供了公共变量的标准接口，如服务的操作计数器。本包通过HTTP在/debug/vars位置以JSON格式导出了这些变量。</p>
    <p align="left">对这些公共变量的读写操作都是原子级的。</p>
    <p align="left">为了增加HTTP处理器，本包注册了如下变量：</p>
    <pre>cmdline   os.Args
memstats  runtime.Memstats</pre>
    <p>有时候本包被导入只是为了获得本包注册HTTP处理器和上述变量的副作用。此时可以如下方式导入本包：</p>
    <pre>import _ "expvar"</pre>
    
    
		
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
    
    <h2 id="Var">type <a href="https://github.com/golang/go/blob/master/src/expvar/expvar.go?name=release#38" title="View Source">Var</a> </h2>
    <pre>type Var interface {
    <span id="Var.String">String</span>() <a href="builtin.htm#string">string</a>
}</pre>
    <p>Var接口是所有导出变量的抽象类型。</p>
    <h2 id="Int">type <a href="https://github.com/golang/go/blob/master/src/expvar/expvar.go?name=release#43" title="View Source">Int</a> </h2>
    <pre>type Int struct {
    <span class="com">// 内含隐藏或非导出字段</span>
}</pre>
    <p>Int代表一个64位整数变量，满足Var接口。</p>
    <h3 id="NewInt">func <a href="https://github.com/golang/go/blob/master/src/expvar/expvar.go?name=release#273" title="View Source">NewInt</a> </h3>
    <pre class="funcdecl">func NewInt(name <a href="builtin.htm#string">string</a>) *<a href="#Int">Int</a></pre>
    <h3 id="Int.Add">func (*Int) <a href="https://github.com/golang/go/blob/master/src/expvar/expvar.go?name=release#54" title="View Source">Add</a> </h3>
    <pre class="funcdecl">func (v *<a href="#Int">Int</a>) Add(delta <a href="builtin.htm#int64">int64</a>)</pre>
    <h3 id="Int.Set">func (*Int) <a href="https://github.com/golang/go/blob/master/src/expvar/expvar.go?name=release#60" title="View Source">Set</a> </h3>
    <pre class="funcdecl">func (v *<a href="#Int">Int</a>) Set(value <a href="builtin.htm#int64">int64</a>)</pre>
    <h3 id="Int.String">func (*Int) <a href="https://github.com/golang/go/blob/master/src/expvar/expvar.go?name=release#48" title="View Source">String</a> </h3>
    <pre class="funcdecl">func (v *<a href="#Int">Int</a>) String() <a href="builtin.htm#string">string</a></pre>
    <h2 id="Float">type <a href="https://github.com/golang/go/blob/master/src/expvar/expvar.go?name=release#67" title="View Source">Float</a> </h2>
    <pre>type Float struct {
    <span class="com">// 内含隐藏或非导出字段</span>
}</pre>
    <p>Float代表一个64位浮点数变量，满足Var接口。</p>
    <h3 id="NewFloat">func <a href="https://github.com/golang/go/blob/master/src/expvar/expvar.go?name=release#279" title="View Source">NewFloat</a> </h3>
    <pre class="funcdecl">func NewFloat(name <a href="builtin.htm#string">string</a>) *<a href="#Float">Float</a></pre>
    <h3 id="Float.Add">func (*Float) <a href="https://github.com/golang/go/blob/master/src/expvar/expvar.go?name=release#79" title="View Source">Add</a> </h3>
    <pre class="funcdecl">func (v *<a href="#Float">Float</a>) Add(delta <a href="builtin.htm#float64">float64</a>)</pre>
    <p>Add adds delta to v.</p>
    <h3 id="Float.Set">func (*Float) <a href="https://github.com/golang/go/blob/master/src/expvar/expvar.go?name=release#86" title="View Source">Set</a> </h3>
    <pre class="funcdecl">func (v *<a href="#Float">Float</a>) Set(value <a href="builtin.htm#float64">float64</a>)</pre>
    <p>Set sets v to value.</p>
    <h3 id="Float.String">func (*Float) <a href="https://github.com/golang/go/blob/master/src/expvar/expvar.go?name=release#72" title="View Source">String</a> </h3>
    <pre class="funcdecl">func (v *<a href="#Float">Float</a>) String() <a href="builtin.htm#string">string</a></pre>
    <h2 id="String">type <a href="https://github.com/golang/go/blob/master/src/expvar/expvar.go?name=release#217" title="View Source">String</a> </h2>
    <pre>type String struct {
    <span class="com">// 内含隐藏或非导出字段</span>
}</pre>
    <p>String代表一个字符串变量，满足Var接口。</p>
    <h3 id="NewString">func <a href="https://github.com/golang/go/blob/master/src/expvar/expvar.go?name=release#291" title="View Source">NewString</a> </h3>
    <pre class="funcdecl">func NewString(name <a href="builtin.htm#string">string</a>) *<a href="#String">String</a></pre>
    <h3 id="String.Set">func (*String) <a href="https://github.com/golang/go/blob/master/src/expvar/expvar.go?name=release#228" title="View Source">Set</a> </h3>
    <pre class="funcdecl">func (v *<a href="#String">String</a>) Set(value <a href="builtin.htm#string">string</a>)</pre>
    <h3 id="String.String">func (*String) <a href="https://github.com/golang/go/blob/master/src/expvar/expvar.go?name=release#222" title="View Source">String</a> </h3>
    <pre class="funcdecl">func (v *<a href="#String">String</a>) String() <a href="builtin.htm#string">string</a></pre>
    <h2 id="Func">type <a href="https://github.com/golang/go/blob/master/src/expvar/expvar.go?name=release#236" title="View Source">Func</a> </h2>
    <pre>type Func func() interface{}</pre>
    <p>Func通过调用函数并将结果编码为json，实现了Var接口。</p>
    <h3 id="Func.String">func (Func) <a href="https://github.com/golang/go/blob/master/src/expvar/expvar.go?name=release#238" title="View Source">String</a> </h3>
    <pre class="funcdecl">func (f <a href="#Func">Func</a>) String() <a href="builtin.htm#string">string</a></pre>
    <h2 id="KeyValue">type <a href="https://github.com/golang/go/blob/master/src/expvar/expvar.go?name=release#100" title="View Source">KeyValue</a> </h2>
    <pre>type KeyValue struct {
    <span id="KeyValue.Key">Key</span>   <a href="builtin.htm#string">string</a>
    <span id="KeyValue.Value">Value</span> <a href="#Var">Var</a>
}</pre>
    <p>KeyValue代表Map中的一条记录。（键值对）</p>
    <h2 id="Map">type <a href="https://github.com/golang/go/blob/master/src/expvar/expvar.go?name=release#93" title="View Source">Map</a> </h2>
    <pre>type Map struct {
    <span class="com">// 内含隐藏或非导出字段</span>
}</pre>
    <p>Map代表一个string到Var的映射变量，满足Var接口。</p>
    <h3 id="NewMap">func <a href="https://github.com/golang/go/blob/master/src/expvar/expvar.go?name=release#285" title="View Source">NewMap</a> </h3>
    <pre class="funcdecl">func NewMap(name <a href="builtin.htm#string">string</a>) *<a href="#Map">Map</a></pre>
    <h3 id="Map.Init">func (*Map) <a href="https://github.com/golang/go/blob/master/src/expvar/expvar.go?name=release#122" title="View Source">Init</a> </h3>
    <pre class="funcdecl">func (v *<a href="#Map">Map</a>) Init() *<a href="#Map">Map</a></pre>
    <h3 id="Map.Get">func (*Map) <a href="https://github.com/golang/go/blob/master/src/expvar/expvar.go?name=release#141" title="View Source">Get</a> </h3>
    <pre class="funcdecl">func (v *<a href="#Map">Map</a>) Get(key <a href="builtin.htm#string">string</a>) <a href="#Var">Var</a></pre>
    <h3 id="Map.Set">func (*Map) <a href="https://github.com/golang/go/blob/master/src/expvar/expvar.go?name=release#147" title="View Source">Set</a> </h3>
    <pre class="funcdecl">func (v *<a href="#Map">Map</a>) Set(key <a href="builtin.htm#string">string</a>, av <a href="#Var">Var</a>)</pre>
    <h3 id="Map.Add">func (*Map) <a href="https://github.com/golang/go/blob/master/src/expvar/expvar.go?name=release#154" title="View Source">Add</a> </h3>
    <pre class="funcdecl">func (v *<a href="#Map">Map</a>) Add(key <a href="builtin.htm#string">string</a>, delta <a href="builtin.htm#int64">int64</a>)</pre>
    <h3 id="Map.AddFloat">func (*Map) <a href="https://github.com/golang/go/blob/master/src/expvar/expvar.go?name=release#177" title="View Source">AddFloat</a> </h3>
    <pre class="funcdecl">func (v *<a href="#Map">Map</a>) AddFloat(key <a href="builtin.htm#string">string</a>, delta <a href="builtin.htm#float64">float64</a>)</pre>
    <p>AddFloat向索引key对应的值（底层为*Float）修改为加上delta后的值。</p>
    <h3 id="Map.Do">func (*Map) <a href="https://github.com/golang/go/blob/master/src/expvar/expvar.go?name=release#202" title="View Source">Do</a> </h3>
    <pre class="funcdecl">func (v *<a href="#Map">Map</a>) Do(f func(<a href="#KeyValue">KeyValue</a>))</pre>
    <p>Do对映射的每一条记录都调用f。迭代执行时会锁定该映射，但已存在的记录可以同时更新。</p>
    <h3 id="Map.String">func (*Map) <a href="https://github.com/golang/go/blob/master/src/expvar/expvar.go?name=release#105" title="View Source">String</a> </h3>
    <pre class="funcdecl">func (v *<a href="#Map">Map</a>) String() <a href="builtin.htm#string">string</a></pre>
    <h2 id="Get">func <a href="https://github.com/golang/go/blob/master/src/expvar/expvar.go?name=release#265" title="View Source">Get</a> </h2>
    <pre class="funcdecl">func Get(name <a href="builtin.htm#string">string</a>) <a href="#Var">Var</a></pre>
    <p>Get获取名为name的导出变量。</p>
    <h2 id="Publish">func <a href="https://github.com/golang/go/blob/master/src/expvar/expvar.go?name=release#253" title="View Source">Publish</a> </h2>
    <pre class="funcdecl">func Publish(name <a href="builtin.htm#string">string</a>, v <a href="#Var">Var</a>)</pre>
    <p>Publish声明一个导出变量。必须在init函数里调用。如果name已经被注册，会调用log.Panic。</p>
    <h2 id="Do">func <a href="https://github.com/golang/go/blob/master/src/expvar/expvar.go?name=release#300" title="View Source">Do</a> </h2>
    <pre class="funcdecl">func Do(f func(<a href="#KeyValue">KeyValue</a>))</pre>
    <p>Do对导出变量的每一条记录都调用f。迭代执行时会锁定全局变量映射，但已存在的记录可以同时更新。</p>
</div>